package com.example.makerspace.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.makerspace.domain.NoticeDO;
import com.example.makerspace.dto.Pagination;
import com.example.makerspace.mapper.NoticeMapper;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
public class NoticeDAO extends BaseDAO<NoticeDO> {
    public final static String TITLE = "title";
    @Resource
    private NoticeMapper noticeMapper;

    @PostConstruct
    public void init(){
        this.mapper = noticeMapper;
    }

    public IPage<NoticeDO> selectByPage(Pagination pagination, int competitionParentId) {
        QueryWrapper<NoticeDO> wrapper = new QueryWrapper<>();
        wrapper.eq("competition_parent_id",competitionParentId);
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }

    public IPage<NoticeDO> selectByPage2(Pagination pagination) {
        QueryWrapper<NoticeDO> wrapper = new QueryWrapper<>();
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }

    public IPage<NoticeDO> selectByLike(Pagination pagination, String title, int competitionParentId) {
        QueryWrapper<NoticeDO> wrapper = new QueryWrapper<>();
        wrapper.eq("competition_parent_id",competitionParentId);
        wrapper.eq(TITLE,title);
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }

    public IPage<NoticeDO> selectByLike2(Pagination pagination, String title) {
        QueryWrapper<NoticeDO> wrapper = new QueryWrapper<>();
        wrapper.eq(TITLE,title);
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }
}
